#include <tut.h>
#include <boost/shared_ptr.hpp>

using namespace boost;

namespace tut
{
    struct shared_ptr_data
    {
        struct keepee{ int data; };
    };

    typedef test_group<shared_ptr_data> testgroup;
    typedef testgroup::object testobject;
    testgroup shared_ptr_testgroup("shared_ptr");

    /**
     * Checks default constructor.
     */
    template<>
    template<>
    void testobject::test<1>()
    {
        shared_ptr<keepee> def;
        ensure("null",def.get() == 0);
    }

    /**
     * Checks operator -> throws instead of returning null.
     */
    template<>
       template<>
       void testobject::test<2>()
       {
          try
          {
             // fail("exception expected");
          }
          catch( const std::runtime_error& )
          {
             // ok
          }
       }

    /**
     * Checks keepee counting.
     */
    template<>
       template<>
       void testobject::test<3>()
       {
          shared_ptr<keepee> sp1(new keepee());
          shared_ptr<keepee> sp2(sp1);
          ensure_equals("second copy at sp1",sp1.use_count(),2);
          ensure_equals("second copy at sp2",sp2.use_count(),2);
       }
};

